package cn.com.fssg.platform.base.handler.impl.zynlpg;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import cn.com.fssg.platform.biz.BizUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;

/**
 * @Description: 我的商协会查询表单数据
 */
@Component
public class ReviewProcess implements InterfaceHandler {

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;
//    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantMainJdbcTemplate();

    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        //获取调用方法0、新增审核信息；1、修改岗位状态
        String state = jsonObject.getString("state");
        String sql = "";
        switch (state){
            case "0":
                int auditResult = Integer.parseInt(jsonObject.getString("career_audit_result"));
                String createBy = jsonObject.getString("career_submitted_by");
                jsonObject.put("career_id", jsonObject.getString("id"));
                jsonObject.put("id", BizUtil.cur().getSnowflakeIdStr());
                jsonObject.put("career_audittime", new Date());
                jsonObject.put("career_submitted_by", createBy == null||createBy.equals("") ? BizUtil.cur().curUserId() : createBy);
                jsonObject.put("career_audit_by", BizUtil.cur().curUserId());
                jsonObject.put("career_audit_result", auditResult);
                sql = "INSERT INTO cmotd_career_examine (" +
                        "id, career_id, career_audittime, career_audit_suggestion, career_submitted_by, career_audit_by, career_audit_result) values " +
                        "(:id, :career_id, :career_audittime, :career_audit_suggestion, :career_submitted_by, :career_audit_by, :career_audit_result)";
                jdbcTemplate.update(sql, jsonObject);
                jsonObject.put("id", jsonObject.getString("career_id"));
                jsonObject.put("career_state", auditResult == 0 ? 4 : 3);
                sql = "UPDATE cmotd_career SET career_state = CAST(:career_state AS SMALLINT), update_by = :career_audit_by WHERE id = :id";
                jdbcTemplate.update(sql, jsonObject);
                break;
            case "1":
                sql = "UPDATE cmotd_career SET career_state = CAST(:career_state AS SMALLINT) WHERE id = :id";
                jdbcTemplate.update(sql, jsonObject);
                break;
            default:
                break;
        }
        return null;
    }
}
